package com.qingzhuge.web.security;

import com.qingzhuge.controller.base.AbstractController;
import com.qingzhuge.controller.security.ControllerSecurityBody;
import com.qingzhuge.controller.security.RsaKey;
import com.qingzhuge.dto.response.ResponseBodyDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author : zero.xiao
 * @description :
 * @date : 2019/10/3 16:58
 * @email: zero.xiao@xiaoyin.org
 */
@Api(tags = "S系统数据安全加密",description = "数据安全加密,需要加密的数据参数用@SecurityParameter 注解，调用端获取公钥对数据进行加密，后台服务接口通过扫描注解@SecurityParameter，需要解密的参数服务器用私钥进行解密")
@RestController
@RequestMapping("api/open")
public class SysApiDataEncryptionController extends AbstractController {
    @Resource
    private ControllerSecurityBody controllerSecurityBody;

    @ApiOperation(value = "获取公钥")
    @PostMapping("public_key")
    public ResponseEntity<ResponseBodyDto<String>> getPublicKey(){
        RsaKey rsaKey = controllerSecurityBody.get();
        String privateKey = null;
        if(null != rsaKey) {
            privateKey = rsaKey.getPrivateKey();
        }
       return returnSuccess(privateKey);
    }
}
